//===========================================================================
//                     __________       __
//                    * Copyright* 2006*  * 2007
//                    +=====+    *_____*  *
//                         /  * Hanli Zhao@ Swalloware
//                       /  / *   =====   *
//                     /   /  *  *     *  *
//                   +    +===+  *     *  +=====+
//                   *___________*     *________*
//
//                         "Spring swallows,
//          that resided in the front of courtyard of lords,
//               enter the house of ordinary citizens."
//          by Yuxi Liu, famous poet of Tang Dynasty of China
//
//                   mailto:Swalloware@gmail.com
//
//===========================================================================
#pragma once
//#include "Swalloware.h"
//#include "SViewFrustum.h"

// First person view camera
class SCamera
{
public:
	SCamera(void);
	~SCamera(void);
	// set view matrix
	void SetDefaultViewParams() { SetViewParams(&mvDefaultEye, &mvDefaultLookAt); }
	void SetViewParams( D3DXVECTOR3* pvEyePos, D3DXVECTOR3* pvLookAtPos );
	// set projection matrix
	void SetProjParams( float fFOV, float fAspect, float fNearPlane, float fFarPlane );
	// set rotation & move scalers
	inline void SetScalers(float fMoveScaler = 1.f, float fRotationScaler = 0.003f)
	{
		mfMoveScaler    = fMoveScaler;
		mRotationScaler = fRotationScaler;
	}
    // Functions to get state
	inline D3DXMATRIX *GetViewMatrix() { return &mmxView; }
	inline D3DXMATRIX *GetProjMatrix() { return &mmxProj; }
	inline D3DXMATRIX *GetWorldMatrix() { return &mmxInvView; }
	inline D3DXVECTOR3 *GetEyePos()    { return &mvEye; }
	inline D3DXVECTOR3 *GetLookAtPos() { return &mvLookAt; }
	inline D3DXVECTOR2 *GetNearFarPlane() { return &mvNearFarPlane; }
	// release mouse event
	void  LockMouse();
	// update camera (view & projection matrixes)
	bool OnFrameMove(float fElapsedTime);
	void OnMouseEvent(int x, int y, bool bMouseLocked);
	void OnKeyEvent(int key, bool bKeyLocked);

	bool bLeftButtonDown;
	LRESULT HandleMessages( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );

	// get corresponding view frustum
	//SViewFrustum *GetViewFrustum(){ return &mFrustum; }
	float mRotationScaler, mfMoveScaler;



protected:
	bool ProcessEvent(float fElapsedTime);
	//SViewFrustum mFrustum;
	// View matrix & projection matrix
    D3DXMATRIX  mmxView, mmxProj, mmxInvView;
	// Camera eye position & lookAt position
    D3DXVECTOR3 mvDefaultEye, mvDefaultLookAt;
    D3DXVECTOR3 mvEye, mvLookAt;
	D3DXVECTOR2 mvMousePos, mvMouseLockedPos;
	D3DXVECTOR2 mvRotAngle, mvNearFarPlane;
	BYTE  mKeyMask;
};
